package org.csu.ssm_backend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.csu.ssm_backend.domain.ProductInfo;
import org.csu.ssm_backend.persistence.ProductMapper;
import org.csu.ssm_backend.persistence.ProductPicMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Service;

@Service
@MapperScan("org.csu.ssm_backend.persistence")
public class ProductPicService {
    @Resource
    private ProductPicMapper productPicMapper;

    ProductPicService(){}

    public void updateProductPic(String productId,byte[] productPicInfo){
        QueryWrapper<ProductInfo> updateWrapper = new QueryWrapper<>();
        ProductInfo productInfo = new ProductInfo();
        productInfo.setProductId(productId);
        productInfo.setPicInfo(productPicInfo);
        updateWrapper.eq("productId",productId);
        productPicMapper.update(productInfo,updateWrapper);
    }

    public void insertProductPic(String productId,byte[] productPicInfo){
        ProductInfo productInfo = new ProductInfo();
        productInfo.setProductId(productId);
        productInfo.setPicInfo(productPicInfo);
        productPicMapper.insert(productInfo);
    }

    public byte[] selectProductPic(String productId){
        QueryWrapper<ProductInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("productId",productId);
        return productPicMapper.selectOne(queryWrapper).getPicInfo();
    }

}
